/*
 * Created on Wed Jun 06 2018 by Ronnie Ren (zhaosong.ren) from Accenture
 *
 * Copyright (c) 2018 DingXing information & technology limited company.
 */

import { Injectable } from "@angular/core";
// import { UserService } from "../models/transform.service";
import { SqliteService } from "../../../services/sqliteDB/sqlite.service";
// import { BillService } from "./bill.service";

import {JsonMappingUtil} from "../../json-mapping-util";
import {InspectionOperations} from '../../transform/inspection/inspection-operations';
import {InspectionOperationsDto} from '../../dto/inspection/inspection-operations.dto';
import {Observable} from "../../../../../../node_modules/rxjs";
import {InspectionRecordsDto} from "../../dto/inspection/inspection-records.dto";
import {SyncStatus} from "../../sync-status";
import {InspectionRecords} from "../../transform/inspection/inspection-records";



@Injectable()
export class InspectionOperationsService {

    constructor(private sqliteService: SqliteService) {

    }

    simpleFetch() {
        this.sqliteService.simpleFetch(InspectionOperationsDto).then( (results) => {
            console.log(results["results"]);
        });
    }

    fetchByCondition() {
        this.sqliteService.fetch(InspectionOperationsDto, {
            filter: [],
            and: {

            },
            // or: [{
            //     price: 32,
            // }, {
            //     price: 1,
            // }],
            // like: {
            //     updateTime: "232"
            // },
            page: {
                pageNo: 1,
                pageSize: 10
            }
        }).then( (results) => {
            console.log(JSON.stringify(results));
        });
    }

    addDevice(obj) {
      if (Array.isArray(obj)) {
        obj.forEach((item, index) => {
          this.add(item);
        });
      } else {
        this.add(obj);
      }
    }

    add(obj) {
      let InspectionOperationsDtoObj = new InspectionOperationsDto();
      let test = new InspectionOperations(obj);
      JsonMappingUtil.MappingAllProp(test, InspectionOperationsDtoObj);
      // console.log(UserDtoObj);
      this.sqliteService.add(InspectionOperationsDtoObj)
        .then( (results) => {
          console.log(JSON.stringify(results));
        })
        .catch( (e) => {
          console.error(e);
        });
    }

    update() {
        // this.sqliteService.update(DeviceDto,
        //     {name : "123313", type: "账号"}, {
        //         and: {
        //             // id: 4
        //         }
        //     }).then( (results) => {
        //     console.log(JSON.stringify(results));
        // });
    }

    remove() {
        this.sqliteService.remove(InspectionOperationsDto, {
            and: {
                areaId: "510000",
            },
            // or: [{
            //     price: 3,
            // }]
        });
    }

    addColumn() {
        this.sqliteService.addColumn(InspectionOperationsDto, {
            imgss: "text"
        });
    }

    dropTable() {
        this.sqliteService.dropTable(InspectionOperationsDto);
    }


}
